import { Injectable, Logger } from "@nestjs/common";
import { serverConfig } from "@/common/config";
import * as fs from "fs";
import * as path from "path";

function readAllFilesInDir(dir: string) {
  const files = fs.readdirSync(dir);
  const result: string[] = [];

  files.forEach((file) => {
    const filePath = path.join(dir, file);
    const stats = fs.statSync(filePath);

    if (stats.isFile()) {
      result.push(filePath);
    } else if (stats.isDirectory()) {
      const subFiles = readAllFilesInDir(filePath); // 递归调用读取子文件夹中的文件
      result.push(...subFiles);
    }
  });

  return result;
}
@Injectable()
export class ConfigService {
  config() {
    const projectPath = process.cwd();

    Logger.log(" ConfigService 日志 ", projectPath, " Service ");
    Logger.log(
      " ConfigService 日志 ",
      process.env.NODE_ENV,
      " process.env.NODE_ENV ",
    );

    let files: any[] = [];
    if (process.env.NODE_ENV === "development") {
      // 使用方法示例
      files = readAllFilesInDir(projectPath + "/dist/html/default");
    } else {
      files = readAllFilesInDir(projectPath + "/html/default");
    }
    const baseUrl = serverConfig.IMG_baseUrl;

    return {
      projectPath: projectPath,
      files: files,
      weixin_QRcode: `${baseUrl}/html/HomeImgList/WX.png`, //客服微信二维码地址
      phone: 13341963929,
      HomepageImg: [
        {
          img: `${baseUrl}/html/HomeImgList/index_1.jpg`,
          title: "1000DA",
          url: "",
        },
        {
          img: `${baseUrl}/html/HomeImgList/index_2.jpg`,
          title: "1000DA",
          url: "",
        },
      ],
      IconImgList: [
        ...files.map((file) => {
          const fileName = file.match(/\w+.png/);
          return {
            key: fileName[0].split(".")[0],
            img: `${baseUrl}/html/default/${fileName}`,
          };
        }),
        {
          text: "客服微信",
          key: "kfwx1",
          img: `${baseUrl}/html/IconImgList/kfwx1.png`,
        },
        {
          text: "客服微信",
          key: "kfwx2",
          img: `${baseUrl}/html/IconImgList/kfwx2.png`,
        },
        {
          text: "客服微信",
          key: "kfwx3",
          img: `${baseUrl}/html/IconImgList/kfwx3.png`,
        },
        {
          text: "客服微信",
          key: "kfwx4",
          img: `${baseUrl}/html/IconImgList/kfwx4.png`,
        },
        {
          text: "上传图片",
          key: "Upload_images",
          img: `${baseUrl}/html/IconImgList/shangchuantupian.png`,
        },
        {
          text: "上传视频",
          key: "Upload_video",
          img: `${baseUrl}/html/IconImgList/shangchuanshipin2.png`,
        },
        {
          text: "联系方式-手机-电话号码",
          key: "mobile_phone",
          img: `${baseUrl}/html/IconImgList/shouji.png`,
        },
        {
          text: "预算",
          key: "budget",
          img: `${baseUrl}/html/IconImgList/yusuanyuchengbenguanli.png`,
        },
        {
          text: "定位",
          key: "location",
          img: `${baseUrl}/html/IconImgList/weizhi.png`,
        },
        {
          text: "定位",
          key: "location2",
          img: `${baseUrl}/html/IconImgList/weizhixiangqing.png`,
        },
        {
          text: "区域",
          key: "weizhixiangqing",
          img: `${baseUrl}/html/IconImgList/weizhixiangqing.png`,
        },
        {
          text: "付款方式",
          key: "Payment",
          img: `${baseUrl}/html/IconImgList/dingdandaifukuan.png`,
        },
        {
          text: "公司",
          key: "company",
          img: `${baseUrl}/html/IconImgList/gongsi.png`,
        },
        {
          text: "姓名",
          key: "full_name",
          img: `${baseUrl}/html/IconImgList/xingming.png`,
        },
        {
          text: "姓名",
          key: "full_name1",
          img: `${baseUrl}/html/IconImgList/xingming1.png`,
        },
        {
          text: "备注",
          key: "remarks",
          img: `${baseUrl}/html/IconImgList/beizhu.png`,
        },
        {
          text: "电站信息",
          key: "power",
          img: `${baseUrl}/html/IconImgList/dianzhanxinxi.png`,
        },
        {
          text: "装机容量",
          key: "KVA",
          img: `${baseUrl}/html/IconImgList/zhuangjirongliang1.png`,
        },
        {
          text: "装机容量",
          key: "KVA1",
          img: `${baseUrl}/html/IconImgList/zhuangjirongliang.png`,
        },
        {
          text: "发电量",
          key: "Power_generation",
          img: `${baseUrl}/html/IconImgList/fadianliang.png`,
        },
        {
          text: "电价",
          key: "Power_generation",
          img: `${baseUrl}/html/IconImgList/dianjiacanshu.png`,
        },
        {
          text: "营收",
          key: "yingshou",
          img: `${baseUrl}/html/IconImgList/yingshou.png`,
        },
        {
          text: "营收",
          key: "yingshou1",
          img: `${baseUrl}/html/IconImgList/yingshou1.png`,
        },
        {
          text: "售价",
          key: "pingjunshoujia",
          img: `${baseUrl}/html/IconImgList/pingjunshoujia.png`,
        },
        {
          text: "售价",
          key: "pingjunshoujia1",
          img: `${baseUrl}/html/IconImgList/fatie-shoujia.png`,
        },
        {
          text: "售价",
          key: "pingjunshoujia1",
          img: `${baseUrl}/html/IconImgList/fatie-shoujia.png`,
        },
        {
          text: "描述",
          key: "describe",
          img: `${baseUrl}/html/IconImgList/describe.png`,
        },
        {
          text: "精选",
          key: "jingxuanyoupin",
          img: `${baseUrl}/html/IconImgList/jingxuanyoupin.png`,
        },
        {
          text: "类型",
          key: "jiaqileixing",
          img: `${baseUrl}/html/IconImgList/jiaqileixing.png`,
        },
        {
          text: "明细",
          key: "xiaofeimingxidan",
          img: `${baseUrl}/html/IconImgList/xiaofeimingxidan.png`,
        },
        {
          text: "时间",
          key: "al-icon-rate",
          img: `${baseUrl}/html/IconImgList/al-icon-rate.png`,
        },
        {
          text: "年限",
          key: "gongzuonianxie",
          img: `${baseUrl}/html/IconImgList/gongzuonianxie.png`,
        },
        {
          text: "土地",
          key: "tudiziyuan",
          img: `${baseUrl}/html/IconImgList/tudiziyuan.png`,
        },
        {
          text: "水",
          key: "shuiyuandi",
          img: `${baseUrl}/html/IconImgList/shuiyuandi.png`,
        },
        {
          text: "积雨面积",
          key: "yewei",
          img: `${baseUrl}/html/IconImgList/yewei.png`,
        },
        {
          text: "库容",
          key: "kurong1",
          img: `${baseUrl}/html/IconImgList/kurong1.png`,
        },
        {
          text: "库容",
          key: "kurong",
          img: `${baseUrl}/html/IconImgList/kurong.png`,
        },
        {
          text: "明渠",
          key: "paishuimingqu",
          img: `${baseUrl}/html/IconImgList/paishuimingqu.png`,
        },
        {
          text: "隧洞",
          key: "suidong",
          img: `${baseUrl}/html/IconImgList/suidong.png`,
        },
        {
          text: "盖板",
          key: "goucaocesuogaiban",
          img: `${baseUrl}/html/IconImgList/goucaocesuogaiban.png`,
        },
        {
          text: "压力管",
          key: "yaliguandao",
          img: `${baseUrl}/html/IconImgList/yaliguandao.png`,
        },
        {
          text: "金额2",
          key: "jine_m",
          img: `${baseUrl}/html/IconImgList/jine_m.png`,
        },
        {
          text: "员工",
          key: "yuangongguanli",
          img: `${baseUrl}/html/IconImgList/yuangongguanli-.png`,
        },
        {
          text: "增值税",
          key: "zengzhishui",
          img: `${baseUrl}/html/IconImgList/zengzhishui.png`,
        },
        {
          text: "水资源",
          key: "shuiyuandi",
          img: `${baseUrl}/html/IconImgList/shuiyuandi.png`,
        },
        {
          text: "维修",
          key: "weixiu",
          img: `${baseUrl}/html/IconImgList/weixiu.png`,
        },
        {
          text: "补偿",
          key: "sudubuchang-copy",
          img: `${baseUrl}/html/IconImgList/sudubuchang-copy.png`,
        },
        {
          text: "开支",
          key: "kaizhi",
          img: `${baseUrl}/html/IconImgList/kaizhi.png`,
        },
        {
          text: "成本",
          key: "chengbenfenxi",
          img: `${baseUrl}/html/IconImgList/chengbenfenxi-.png`,
        },
        {
          text: "营收",
          key: "shouyi2",
          img: `${baseUrl}/html/IconImgList/shouyi2.png`,
        },
        {
          text: "营收",
          key: "shouyi2",
          img: `${baseUrl}/html/IconImgList/shouyi2.png`,
        },
      ],
    };
  }
}
